#ifndef AttributeItem_H
#define AttributeItem_H

#include "ModelItems/TreeItem.h"
#include "..\..\core\src\AssetManager.h"
#include "..\..\core\src\container\ResponseAttribute.h"

namespace Xps
{
	class AttributeItem : public TreeItem
	{
	public:
		AttributeItem(XpsAssets::AssetManager* am, int id, int pid = -1) : TreeItem(am,id,ModelItemType::ATTRIBUTE, pid)
		{
			asset = am->getAttribute(id);
			setIcon(QIcon(":/rs/images/attribute.png"));
		};

		QVariant AttributeItem::data (int role) const
		{
			XpsAssets::Attribute* a;
			a = (XpsAssets::Attribute*) asset;
			
			if (role == Qt::EditRole || role == Qt::DisplayRole)
			{
				a = (XpsAssets::Attribute*) asset;
				return QString("%1 %2").arg(a->id(),3,10,QChar('0')).arg(a->name());
			}
				
			return TreeItem::data(role);
		}

		void AttributeItem::setData ( const QVariant & value, int role)
		{
			if (role != Qt::EditRole) 
				return TreeItem::setData(value,role);

			XpsAssets::Attribute* a = (XpsAssets::Attribute*) asset;
			a->setName(value.toString());
		}
	};
}
#endif